/**
 * @filename:SysFieldController 2022年1月27日
 * @project Wonder xhadmin Framework  V1.0
 * Copyright(c) 2020 LuZhongren Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.admin.controller;


import com.wonder.admin.constant.Parameters;
import com.wonder.admin.domain.SysAction;
import com.wonder.admin.domain.SysField;
import com.wonder.admin.domain.SysMenu;
import com.wonder.admin.service.SysActionService;
import com.wonder.admin.service.SysFieldService;
import com.wonder.admin.service.SysMenuService;
import com.wonder.admin.request.SysFieldRequest;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wonder.common.common.AjaxMap;
import com.wonder.common.common.AjaxResult;
import com.wonder.common.common.CommonPage;

import com.wonder.common.utils.MessageUtils;
import com.wonder.common.utils.StringUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**   
 * 
 * <p>说明： 模块字段管理API接口层</P>
 * @version: V1.0
 * @author: LuZhongren
 * @time    2022年1月27日
 *
 */
@Api(tags = "模块字段管理")
@RestController
@RequestMapping("/admin/Sys.Base")
public class SysFieldController {
	
	@Autowired
	private SysFieldService sysFieldService;
	
	@Autowired
	private SysMenuService sysMenuService;
	
	@Autowired
	private SysActionService sysActionService;
	
	@ApiOperation(value = "模块字段管理列表")
	@RequestMapping(value = "/fieldList", method = RequestMethod.POST)
	public Map<String, Object> index(@RequestBody SysFieldRequest sysFieldRequest) {
		
		Page<SysField> page = new Page<SysField>(sysFieldRequest.getPage(), sysFieldRequest.getLimit());
		IPage<SysField> list = sysFieldService.selectList(sysFieldRequest, page);
		Map<String, Object> map=new HashMap<>();
		map.put("data", CommonPage.restPage(list));
		map.put("typeField", Parameters.fieldList());
		map.put("itemList", Parameters.itemList());
		SysMenu sysMenu=sysMenuService.getById(sysFieldRequest.getMenu_id());
		map.put("menu_title", sysMenu.getTitle());
		
		return AjaxMap.success(map);
	}

	
	/**
	 * @explain 查询对象  <swagger GET请求>
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/getFieldInfo")
	@ApiOperation(value = "获取模块字段管理对象", notes = "作者：LuZhongren")
	public AjaxResult<SysField> getFieldInfo(@RequestBody Map<String, Object> map){ 
		if(map==null)return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		long id=Long.parseLong(map.get("id").toString());
		SysField sysField=sysFieldService.getById(id);
		if (null!=sysField ) {
			 sysField.setItem_config(null); //
			 
			 @SuppressWarnings("unchecked")
			List<Map<String, Object>> items = JSON.parseObject(sysField.getItem_config_table(), new ArrayList<Map<String, Object>>().getClass());    
			 sysField.setItem_config(items);
			 if(sysField.getOther_config_table()!=null) {
				 @SuppressWarnings("unchecked")
				 Map<String, Object> other_items = JSON.parseObject(sysField.getOther_config_table(), new HashMap<String, Object>().getClass());
				 sysField.setOther_config(other_items);
			 }
			 String[] validate= {""};
			 if(StringUtils.hasText(sysField.getValidate_table())) 
			    sysField.setValidate(StringUtils.splitPreserveAllTokens(sysField.getValidate_table(), ","));
			 else {
				 sysField.setValidate(validate);
			}

			
			 return AjaxResult.success(sysField);
		}else {
			 return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		}
		
	}
	
	/**
	 * @explain 查询对象  <swagger GET请求>
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/getTableFields")
	@ApiOperation(value = "获取模块主表字段", notes = "作者：LuZhongren")
	public Map<String, Object> getTableFields(@RequestBody Map<String, Object> map){ 
		if(map==null)return AjaxMap.failed(MessageUtils.message("search.not.exist"));
		
		String controller_name=map.get("controller_name").toString();
		if(!StringUtils.hasText(controller_name)) return AjaxMap.failed(MessageUtils.message("search.not.exist"));
		SysMenu sysMenu=sysMenuService.getOne(new QueryWrapper<SysMenu>().eq("controller_name", controller_name).ne("table_name", ""));
		if(sysMenu==null) return AjaxMap.failed(MessageUtils.message("search.not.exist"));
		
		return AjaxMap.success("fieldList",sysFieldService.getTableFields(sysMenu.getTable_name()));
	}
	
	
	/**
	 * @explain 删除对象
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/deleteField")
	@ApiOperation(value = "删除字段", notes = "作者：LuZhongren")
	public Map<String, Object> deleteField(@RequestBody Map<String, Object> map){
		if(map==null)return AjaxMap.failed(MessageUtils.message("search.not.exist"));
		Long menu_id=Long.parseLong(map.get("menu_id").toString());
		String ids=map.get("id").toString();
		ids=StringUtils.remove(ids, '[');
		ids=StringUtils.remove(ids, ']');
		
		String[] fieldIds=StringUtils.split(ids, ',');
		List<Long> idList=new ArrayList<>(); 
		for(int i=0;i<fieldIds.length;i++)
		{
			idList.add( Long.parseLong(fieldIds[i].trim()));//整数数组
		}
		List<SysField> sysFields=sysFieldService.listByIds(idList);
		SysMenu sysMenu=sysMenuService.getById(menu_id);
	    boolean pk_status=false;
	    //We will not delete the primary key
	    for (SysField item : sysFields) {
	    	if(item.getField()==sysMenu.getPk()) {
	    		pk_status=true;
	    		idList.remove(item.getId());    		
	    	}
	    }
	
	    Map<String, Object> map1=new HashMap<String, Object>();
	    map1.put("pk_status", pk_status);
	    
		if (null!=sysFields) {
		  boolean rsg = sysFieldService.removeBatchByIds(idList);
		  if (rsg) {
			    return AjaxMap.success(map1);
		  }else {
			   return AjaxMap.failed(map1,MessageUtils.message("delete.fail"));
		  }
		}else {
			 return AjaxMap.failed(MessageUtils.message("delete.not.exist"));
		}
	}
	
	/**
	 * @explain 添加
	 * @param   对象参数：SysField
	 * @return  Boolean
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/createField")
	@ApiOperation(value = "添加字段", notes = "作者：LuZhongren")
	public AjaxResult<SysField> createField(@RequestBody SysField entity){

		if (null!=entity) {
			
			entity.setValidate_table(StringUtils.join(entity.getValidate(),","));
			if(entity.getOther_config()==null || entity.getOther_config().isEmpty())
			{
				entity.setOther_config_table(null);
			}else {
				entity.setOther_config_table(JSON.toJSONString(entity.getOther_config()));
			}
			
			if(entity.getItem_config()==null || entity.getItem_config().size()==0)
			{
				entity.setItem_config_table(null);
			}else {
				entity.setItem_config_table(JSON.toJSONString(entity.getItem_config()));
			}
			
			int search_status=0; 
	
			List<Map<String, Object>> fieldList=Parameters.fieldList();
			for(Map<String, Object> item:fieldList) {
				if(item.get("type")==entity.getType() && StringUtils.isEmpty(entity.getBelong_table())){
					search_status=(boolean)item.get("search")?1:0;
				}
			}
			entity.setSearch_type(search_status);
		
			boolean rsg = sysFieldService.save(entity);
			if (rsg) {
				    //Update the sortid the same as the key id
				     sysFieldService.update(new UpdateWrapper<SysField>().set("sortid", entity.getId()).eq("id", entity.getId()));
				  return AjaxResult.success(MessageUtils.message("insert.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("insert.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("insert.parameter.error"));
		}
	}
	
	/**
	 * @explain 修改
	 * @param   对象参数：SysField
	 * @return  Boolean
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/updateField")
	@ApiOperation(value = "修改字段", notes = "作者：LuZhongren")
	public AjaxResult<SysField> updateField(@RequestBody SysField entity){
		if (null!=entity) {
			
			entity.setValidate_table(StringUtils.join(entity.getValidate(),","));
			if(entity.getOther_config()==null || entity.getOther_config().isEmpty())
			{
				entity.setOther_config_table(null);
			}else {
				entity.setOther_config_table(JSON.toJSONString(entity.getOther_config()));
			}
			if(entity.getItem_config()==null || entity.getItem_config().size()==0)
			{
				entity.setItem_config_table(null);
			}else {
				entity.setItem_config_table(JSON.toJSONString(entity.getItem_config()));
			}
			
//			int search_status=0; 
//	
//			List<Map<String, Object>> fieldList=Parameters.fieldList();
//			for(Map<String, Object> item:fieldList) {
//				if(item.get("type")==entity.getType() && StringUtils.isEmpty(entity.getBelong_table())){
//					search_status=(boolean)item.get("search")?1:0;
//				}
//			}
//			entity.setSearch_type(search_status);
			
			boolean rsg = sysFieldService.updateById(entity);
			if (rsg) {
				  return AjaxResult.success(MessageUtils.message("update.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("update.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("update.not.exist"));
		}
	}
	
	/**
	 * @explain 修改状态开关等
	 * @param   对象参数：SysField
	 * @return  Boolean
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/updateFieldExt")
	@ApiOperation(value = "修改单个字段", notes = "作者：LuZhongren")
	public AjaxResult<SysField> updateFieldExt(@RequestBody SysField entity){
		if (null!=entity) {
			boolean rsg = sysFieldService.updateById(entity);
			if (rsg) {
				  return AjaxResult.success(MessageUtils.message("update.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("update.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("update.not.exist"));
		}
	}
	
	/**
	 * @explain 获取表的所有字段
	 * @param   对象参数：table
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/getTableColumns")
	@ApiOperation(value = "获取表的所有字段", notes = "作者：LuZhongren")
	public AjaxResult<List<Map<String, Object>>> getTableColumns(String table){
		
		List<Map<String, Object>> list=sysFieldService.getColumnMapList(table);
		return AjaxResult.success(list);
	
	}
	
	
	/**
	 * @explain 获取数据库表
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/getTables")
	@ApiOperation(value = "获取数据库表", notes = "作者：LuZhongren")
	public AjaxResult<List<String>> getTables(){
		
		List<Map<String, Object>> list=sysFieldService.getTables();
		String[] no_shows= {"sys_menu","sys_field","sys_application","sys_action","sys_formula","sys_oper_log","sys_logininfor"};
		List<String> tables=new ArrayList<String>();
		for(Map<String, Object> item:list) {
			 tables.add(item.get("TABLE_NAME").toString());	
		}
		for(int i=0;i<no_shows.length;i++ )
			if(tables.contains(no_shows[i])) tables.remove(no_shows[i]);
		
		return AjaxResult.success(tables);
	
	}
	
	
	/**
	 * @explain 获取提交字段
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/getPostField")
	@ApiOperation(value = "获取提交字段", notes = "作者：LuZhongren")
	public Map<String, Object> getPostField(@RequestBody Map<String, Object> map){
		if(map==null)return AjaxMap.failed(MessageUtils.message("search.not.exist"));
		Long menu_id=Long.parseLong(map.get("menu_id").toString());
		SysMenu sysMenu=sysMenuService.getById(menu_id);
		List<Map<String, Object>> fieldsList=sysFieldService.listMaps(new QueryWrapper<SysField>()
				.select("type","field","title").eq("menu_id", menu_id).eq("post_status", 1).orderByAsc("sortid"));
		String pk=sysMenu.getPk();
		Map<String, Object> pkField=new HashMap<String, Object>();
		pkField.put("field", pk);
		pkField.put("title", "编号");
		
		List<Map<String, Object>> model_fields=new ArrayList<Map<String,Object>>();
		model_fields.add(pkField);
		model_fields.addAll(fieldsList);
	
	    List<Map<String, Object>> tableList=sysMenuService.listMaps(new QueryWrapper<SysMenu>()
				.select("controller_name").eq("app_id", sysMenu.getApp_id()).ne("table_name", "").notLike("table_name", "sys_"));
//		List<String> tableList=sysMenuService.listObjs(new QueryWrapper<SysMenu>()
//				.select("controller_name").eq("app_id", sysMenu.getApp_id()).ne("table_name", "")).stream()
//		        .map(o -> (String) o)
//		        .collect(Collectors.toList());
		List<SysAction> actionList=sysActionService.list(new QueryWrapper<SysAction>().eq("menu_id", menu_id));
		
		List<Map<String, Object>> with_join=new ArrayList<Map<String,Object>> ();
		for(SysAction v:actionList) {
			if(StringUtils.hasText(v.getWith_join_table()) && (v.getType()==2 || v.getType()==3)) {
				@SuppressWarnings("unchecked")
				List<Map<String, Object>> with_join_items = JSON.parseObject(v.getWith_join_table(),
						new ArrayList<Map<String, Object>>().getClass());
				if(with_join_items!=null && with_join_items.size()>0) {
					for(Map<String, Object> n:with_join_items) {
						List<Map<String, Object>> extendFields=getExtendFields(n);
						n.put("fields", extendFields);
						with_join.addAll(extendFields);
						
					}
				}
			}
		}
		
		
		List<Map<String, Object>> tab_Fields=new ArrayList<Map<String,Object>> ();
		tab_Fields.addAll(fieldsList);
		
		Map<String, Object> newWith_join=new HashMap<>();
		for(Map<String, Object> item:with_join) {
			if(!newWith_join.containsKey(item.get("field"))) {
				item.remove("belong_table");
				item.remove("table_name");
				newWith_join.put(item.get("field").toString(), item);
				
				tab_Fields.add(item);
			}
		}
		
		
		Map<String, Object> mapReturn=new HashMap<>();
		mapReturn.put("data", fieldsList);
		mapReturn.put("model_fields", model_fields);
		mapReturn.put("tab_fields", tab_Fields);
		mapReturn.put("tableList", tableList);
		mapReturn.put("sms_list", Parameters.sms_list());
		
		return AjaxMap.success(mapReturn);
		
		
		
		
//$menuInfo = Menu::find($menu_id);
//		
//		$list = Field::field('type,field,title')->where('menu_id',$menu_id)->where('post_status',1)->order('sortid asc')->select()->toArray();
//		
//		$pk = Db::connect($menuInfo['connect'])->name($menuInfo['table_name'])->getPk();
//		
//		$model_fields = array_merge([['field'=>$pk,'title'=>'编号']],$list);
//		
//		$tableList = Menu::where('table_name','<>','')->where('app_id',$menuInfo['app_id'])->field('controller_name')->select()->toArray();
//		
//		$with_join = [];
//		$actionList = Action::where('menu_id',$menu_id)->select();
//		foreach($actionList as $v){
//			if($v['with_join'] && in_array($v['type'],[2,3])){
//				foreach(json_decode($v['with_join'],true) as $n){
//					$n['fields'] = $this->getExtendFields($n);
//					foreach($n['fields'] as $m){
//						array_push($with_join, $m);
//					}
//				}
//			}
//		}
//		
//		$newWith = [];
//		foreach ($with_join as $key=>$v) {
//			if(isset($newWith[$v['field']]) == false){
//				$newWith[$v['field']] = $v;
//			}
//		}
//		
//		foreach($newWith as $k=>$v){
//			unset($newWith[$k]['belong_table']);
//			unset($newWith[$k]['table_name']);
//		}
//		
//		$tab_fields = array_merge($list,$newWith);
//		return json(['status'=>200,'data'=>$list,'model_fields'=>$model_fields,'tab_fields'=>$tab_fields,'tableList'=>$tableList,'sms_list'=>Config::sms_list()]);
	
	}
	
	private List<Map<String,Object> >getExtendFields(Map<String, Object> map) {
		SysMenu sysMenu=sysMenuService.getOne(new QueryWrapper<SysMenu>().eq("controller_name", map.get("relative_table")));
		List<Map<String,Object>> fieldList=sysFieldService.listMaps(new QueryWrapper<SysField>().eq("menu_id", sysMenu.getMenu_id()).orderByAsc("sortid"));
		List<String> joinFields=new ArrayList<String>();
		if(map.get("fields")!=null) {
			Object obj=map.get("fields");
			if (obj.getClass().isArray()) {
			    int length = Array.getLength(obj);
			    for (int i = 0; i < length; i++) {
			    	joinFields.add( Array.get(obj, i).toString());
			    }
			}
		}
		
		for(Map<String,Object> v:fieldList) {
			v.put("belong_table", map.get("relative_table").toString());
			v.put("table_name", sysMenu.getTable_name());
			if(joinFields.contains(v.get("field").toString())) fieldList.remove(v);
			
		
		}
		return fieldList;
	}
	
	
	/**
	 * @explain 获取表的所有字段
	 * @param   对象参数：table
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/getFields")
	@ApiOperation(value = "从表中添加字段", notes = "作者：LuZhongren")
	public AjaxResult<List<Map<String, Object>>> getFields(@RequestBody Map<String, Object> map){
		
		if(map==null)return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		Long menu_id=Long.parseLong(map.get("menu_id").toString());
		SysMenu sysMenu=sysMenuService.getById(menu_id);

		List<String> existColumns=sysFieldService.getAllField(menu_id);
		
		List<Map<String, Object>> list=sysFieldService.getColumnMapList(sysMenu.getTable_name());
		List<SysField> fields=new ArrayList<SysField>();
		
		for(Map<String, Object> item:list) {
			if(existColumns.contains(item.get("COLUMN_NAME").toString())) continue;
			
			SysField sysField=new SysField();
			sysField.setMenu_id(menu_id);
			sysField.setType(1);
			sysField.setList_show(2);
			sysField.setSearch_type(0);
			sysField.setPost_status(1);
			sysField.setCreate_table_field(0);
			sysField.setField(item.get("COLUMN_NAME").toString());
			
			if(item.get("COLUMN_NAME").toString().equals(sysMenu.getPk())) {
				sysField.setWidth("70");
				sysField.setPost_status(0);
			}
			if(item.get("COLUMN_COMMENT")!=null) {
				sysField.setTitle(item.get("COLUMN_COMMENT").toString());
			}else {
				sysField.setTitle(item.get("COLUMN_NAME").toString());
			}
			String data_type=item.get("DATA_TYPE").toString();
			if(data_type.equals("bigint")) data_type="int";
			if(data_type.equals("timestamp")) data_type="datetime";
			
			sysField.setDatatype(data_type);
			if(item.get("CHARACTER_MAXIMUM_LENGTH")!=null)
				sysField.setLength(item.get("CHARACTER_MAXIMUM_LENGTH").toString());
			if(item.get("NUMERIC_PRECISION") !=null)
				sysField.setLength(item.get("NUMERIC_PRECISION").toString());
				
			fields.add(sysField);
			
		}
		boolean ret=sysFieldService.saveBatch(fields);
		
	    int nums=sysFieldService.updateBatchSortid(menu_id);
		
		
//		 foreach($list as $k=>$v){
//             
//             if(in_array($v['Field'],$fieldList)) continue;
//             
//             $fieldInfo[$k]['menu_id'] = $menu_id;
//             $fieldInfo[$k]['title'] = $v['Comment'] ? $v['Comment'] : $v['Field'];
//             $fieldInfo[$k]['field'] = $v['Field'];
//             $fieldInfo[$k]['type'] = 1;
//             $fieldInfo[$k]['list_type'] = 1;
//             $fieldInfo[$k]['list_show'] = 2;
//             $fieldInfo[$k]['search_type'] = 0;
//             $fieldInfo[$k]['post_status'] = 1;
//             $fieldInfo[$k]['create_table_field'] = 0;
//             $fieldInfo[$k]['sortid'] = $k+1;
//             $fieldInfo[$k]['datatype'] = preg_split("/\(.*\)+/", $v['Type'])[0];
//             preg_match_all("/\((.*)\)/", $v['Type'],$all);
//             $fieldInfo[$k]['length'] = $all[1][0];
//             if($v['Field'] == $pk){
//                     $fieldInfo[$k]['width'] = 70;
//                     $fieldInfo[$k]['post_status'] = 0;
//             }
//     }
		
		return AjaxResult.success();
	
	}
	/**
	 * 字段选项配置，验证规则配置
	 * @return
	 */
	@PostMapping("/configList")
	@ApiOperation(value = "字段选项配置，验证规则配置", notes = "作者：LuZhongren")
	public Map<String, Object> configList() {
		Map<String, Object> retMap=new HashMap<String, Object>();
		retMap.put("ruleList", Parameters.ruleList());
		retMap.put("propertyField", Parameters.propertyField());
		
		return AjaxMap.success(retMap);
	
	}
	
	
	/**
	 * 获取非系统数据表
	 * @return
	 */
	@PostMapping("/getTablesByMenuId")
	@ApiOperation(value = "获取非系统数据表", notes = "作者：LuZhongren")
	public AjaxResult<Object> getTablesByMenuId(@RequestBody Map<String, Object> map) {
		if(map==null) return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		Long menu_id=Long.parseLong(map.get("menu_id").toString());
		SysMenu sysMenu=sysMenuService.getById(menu_id);
		List<Map<String, Object>> tables=sysMenuService.listMaps(new QueryWrapper<SysMenu>()
				.eq("app_id", sysMenu.getApp_id()).ne("table_name", "").notLike("table_name", "sys_").select("table_name","title"));
		
		return AjaxResult.success(tables);
	
	}
	
	
	/**
	 * 获取非系统数据表
	 * @return
	 */
	@PostMapping("/getControllersByMenuId")
	@ApiOperation(value = "获取非系统数据表", notes = "作者：LuZhongren")
	public AjaxResult<Object> getControllersByMenuId(@RequestBody Map<String, Object> map) {
		if(map==null) return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		Long menu_id=Long.parseLong(map.get("menu_id").toString());
		SysMenu sysMenu=sysMenuService.getById(menu_id);
		List<Map<String, Object>> tables=sysMenuService.listMaps(new QueryWrapper<SysMenu>()
				.eq("app_id", sysMenu.getApp_id()).ne("table_name", "").notLike("table_name", "sys_").select("controller_name","title"));
		
		return AjaxResult.success(tables);
	
	}
	
	/**
	 * 拖动排序,暂时疲敝功能
	 * @return
	 */
	@PostMapping("/updateFieldSort")
	@ApiOperation(value = "拖动排序", notes = "作者：LuZhongren")
	public Map<String, Object> updateFieldSort(@RequestBody Map<String, Object> map) {
		if(map==null) return AjaxMap.failed(MessageUtils.message("search.not.exist"));
		Map<String, Object> retMap=new HashMap<String, Object>();
		if(!map.containsKey("preId")) {
			retMap.put("pre",0);
			return AjaxMap.success(retMap);
		}
		//currentId,preId,nextId,menu_id
		Long preFieldId=Long.parseLong(map.get("preId").toString());
		Map<String, Object> sortMap=sysFieldService.getMap(new QueryWrapper<SysField>().eq("id", preFieldId).select("sortid"));
		
		retMap.put("pre",sortMap.get("sortid"));
		
		return AjaxMap.success(retMap);
	
	}
	
	
	
	

	
}